package com.yumeno.education.service.impl;

import com.yumeno.education.dao.QuestionsDao;
import com.yumeno.education.entity.Questions;
import com.yumeno.education.service.QuestionsService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class QuestionsServiceImpl implements QuestionsService {

    @Resource
    private QuestionsDao questionsDao;

    @Override
    public Questions getQuestions() {
        return questionsDao.getQuestions();
    }

    @Override
    public Map<String, Object> add(Questions questions) {
        Map<String,Object> resMap=new HashMap<>();
        Date date=new Date();
        questions.setInsertTime(date);
        if (StringUtils.isEmpty(questions.getHint())){
            questions.setHint("暂无解析");
        }
        int i = questionsDao.add(questions);
        if (i==1){
            resMap.put("res",true);
            resMap.put("msg","添加成功!");
        }else {
            resMap.put("res",false);
            resMap.put("msg","添加失败!");
        }
        return resMap;
    }
}
